package com.sh.suhe.utildemos.views.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sh.suhe.utildemos.R;
import com.sh.suhe.utildemos.dialogUtils.RightDialog;
import com.sh.suhe.utildemos.model.PaPhotoTypeModel;

import java.util.ArrayList;
import java.util.List;

public class PaPhotoTypeAdapter extends RecyclerView.Adapter<PaPhotoTypeAdapter.ViewHolder> {
    List<PaPhotoTypeModel> imgList = new ArrayList<>();
    Context mContext;
    RightDialog.TypeClick typeClick;

    public PaPhotoTypeAdapter(Context context){
        mContext = context;
    }
    @NonNull
    @Override
    public PaPhotoTypeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pa_photo_type,parent,false);
        PaPhotoTypeAdapter.ViewHolder viewHolder = new PaPhotoTypeAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull PaPhotoTypeAdapter.ViewHolder holder, int position) {
        String img = imgList.get(position).getType();
        holder.tv.setText(img);

        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (typeClick != null) {
                    typeClick.clickType(imgList.get(position));
                }
            }
        });
//        LogUtil.e("PaPhotoTypeAdapter", img);
    }

    @Override
    public int getItemCount() {
        return imgList.size();
    }
    public void setImgTypeList(List<PaPhotoTypeModel> imgs){
        imgList.clear();
        imgList.addAll(imgs);
    }

    public void setTypeClick(RightDialog.TypeClick typeClick) {
        this.typeClick = typeClick;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView tv;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.pa_photo_type);
        }
    }
}
